package com.tang.framework.config.mybatisPlus;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.tang.common.constant.Constant;
import com.tang.common.properties.sys.CoolTeaProperties;
import com.tang.framework.component.TokenService;
import com.tang.framework.config.mybatisPlus.interceptor.CustomizeMultiDataPermissionHandler;
import com.tang.framework.config.mybatisPlus.interceptor.CustomizeTenantLineHandler;
import com.tang.framework.config.mybatisPlus.interceptor.CustomizeTenantLineInnerInterceptor;
import com.tang.framework.core.model.LoginUser;
import net.sf.jsqlparser.expression.StringValue;
import org.apache.commons.lang3.StringUtils;
import net.sf.jsqlparser.expression.Expression;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

import java.util.Objects;

@SpringBootConfiguration
public class MybatisPlusConfig {


    @Resource
    private TokenService tokenService;


    @Resource
    private HttpServletRequest request;

    @Resource
    private RedissonClient redissonClient;


    @Resource
    private CoolTeaProperties coolTeaProperties;


    @Resource
    private CustomizeTenantLineHandler customizeTenantLineHandler;

    @Resource
    private CustomizeMultiDataPermissionHandler customizeMultiDataPermissionHandler;

    /**
     * 新版
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();

        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //租户
        mybatisPlusInterceptor.addInnerInterceptor(new CustomizeTenantLineInnerInterceptor(customizeTenantLineHandler));
        //数据权限
        mybatisPlusInterceptor.addInnerInterceptor(new DataPermissionInterceptor(customizeMultiDataPermissionHandler));
        //分页
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());

        return mybatisPlusInterceptor;
    }


}
